[Android] Properly handle requestDisallowInterceptTouchEvent for v3 - #4367
Open
j-piasecki wants to merge 1 commit into
Open
[Android] Properly handle requestDisallowInterceptTouchEvent for v3#4367j-piasecki wants to merge 1 commit into
requestDisallowInterceptTouchEvent for v3#4367j-piasecki wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts Android’s requestDisallowInterceptTouchEvent handling to avoid canceling v3 gestures too broadly (notably inside pagers), by making cancellation more targeted across root/orchestrator and v3 detector/button views.
Changes:
- Add
GestureHandlerOrchestrator.cancelAllLegacyHandlers()and use it from the root helper instead of triggering cancellation via the internal root handler. - Override
requestDisallowInterceptTouchEventin v3 host detector and button view to cancel only relevant handlers (and skip cancellation while the orchestrator is handling touch). - Update root view lookup to prefer the nearest enabled
RNGestureHandlerRootViewand expose the orchestrator via the root view/root helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt | Exposes orchestrator and returns nearest enabled GH root view when searching ancestors. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt | Switches root-level cancellation to cancelAllLegacyHandlers and attaches root handler with ACTION_TYPE_NONE. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt | Adds requestDisallowInterceptTouchEvent override to cancel v3 handlers attached via the host detector. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt | Adds requestDisallowInterceptTouchEvent override to cancel the button’s managed v3 handler. |
| packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt | Introduces cancelAllLegacyHandlers() to selectively cancel v1/v2 action types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
j-piasecki
force-pushed
the
jpiasecki/handle-request-disallow
branch
2 times, most recently
from
July 31, 2026 09:14
3c9f4bc to
934af71
Compare
j-piasecki
force-pushed
the
jpiasecki/handle-request-disallow
branch
from
July 31, 2026 09:25
934af71 to
c30a19c
Compare
j-piasecki
marked this pull request as ready for review
July 31, 2026 11:34
m-bert
approved these changes
Jul 31, 2026
Comment on lines
+58
to
+67
| val currentHandlers = attachedHandlers.mapNotNull { tag -> | ||
| RNGestureHandlerModule.registries[this.moduleId]?.getHandler(tag) | ||
| }.filter { | ||
| // The handler has been recorded | ||
| it.view != null | ||
| } | ||
|
|
||
| currentHandlers.forEach { | ||
| it.cancel() | ||
| } |
Collaborator
There was a problem hiding this comment.
Can't we do it simpler?
Suggested change
| val currentHandlers = attachedHandlers.mapNotNull { tag -> | |
| RNGestureHandlerModule.registries[this.moduleId]?.getHandler(tag) | |
| }.filter { | |
| // The handler has been recorded | |
| it.view != null | |
| } | |
| currentHandlers.forEach { | |
| it.cancel() | |
| } | |
| val registry = RNGestureHandlerModule.registries[moduleId] ?: return | |
| for (tag in attachedHandlers) { | |
| registry.getHandler(tag)?.takeIf { it.view != null }?.cancel() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Android, when a native view calls
requestDisallowInterceptTouchEvent(e.g. a pager starting a swipe),RNGestureHandlerRootViewreacted by cancelling all handlers registered on the root.react-native-pager-viewcalls it eagerly on touch down, so any v3 gesture rendered inside a pager (e.g. inside material top tabs) was cancelled before it could activate — a long press nested in top tabs never activated at all.This PR makes the cancellation targeted:
GestureHandlerOrchestrator.cancelAllLegacyHandlers, instead of the old trick of activating the internalRootViewGestureHandler. The root handler is now attached withACTION_TYPE_NONEso it's excluded from that sweep (and no longer sends dead events to JS).requestDisallowInterceptTouchEventoverrides onRNGestureHandlerDetectorViewandButtonViewGroup. Since the request only bubbles upward from the requesting view, only handlers attached to its ancestors are cancelled — handlers below the requester (like the long press under the pager) keep working.isHandlingTouch), mirroring the existingpassingTouchguard, so disallow requests caused by RNGH's own event delivery don't cancel gestures.findGestureHandlerRootViewnow returns the nearest enabled root view so the checks above consult the orchestrator that actually manages the subtree.Test plan
Tested on reproducer from #2383
Screen.Recording.2026-07-31.at.11.38.38.mov